package com.whlilong.jxc.util;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Table;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;

import com.whlilong.jxc.constants.IAppConstants;
import com.whlilong.jxc.model.Sysfun;


public class ViewerChange {
private static ViewerChange single = new ViewerChange();
private IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
	
	private ViewerChange(){}
	
	public static ViewerChange getInstance(){
		if(single == null){
			single = new ViewerChange();
		}
		return single;
	}
	
	public void refreshView(Table table) {
		// TODO Auto-generated method stub

		Sysfun sysfun = (Sysfun) table.getItem(table.getSelectionIndex())
				.getData();
		int sysno = sysfun.getId();
		switch (sysno) {
		case 1:
			try {
				window.getActivePage().showView(
						IAppConstants.fileManagerView_id, null,
						IWorkbenchPage.VIEW_VISIBLE);// 切换视图IWorkbenchPage.VIEW_VISIBLE
			} catch (PartInitException e) {
				MessageDialog.openError(window.getShell(), "出错", "无法打开视图！");
			}
			break;
		case 2:
			try {
				window.getActivePage().showView(
						IAppConstants.purchasManagerView_id, null,
						IWorkbenchPage.VIEW_VISIBLE);
			} catch (PartInitException e) {
				MessageDialog.openError(window.getShell(), "出错", "无法打开视图！");
			}
			break;
		case 3:
			try {
				window.getActivePage().showView(
						IAppConstants.productManagerView_id, null,
						IWorkbenchPage.VIEW_VISIBLE);
			} catch (PartInitException e) {
				MessageDialog.openError(window.getShell(), "出错", "无法打开视图！");
			}
			break;
		case 4:
			try {
				window.getActivePage().showView(
						IAppConstants.storeManagerView_id, null,
						IWorkbenchPage.VIEW_VISIBLE);
			} catch (PartInitException e) {
				MessageDialog.openError(window.getShell(), "出错", "无法打开视图！");
			}
			break;
		case 5:
			try {
				window.getActivePage().showView(
						IAppConstants.queryStatisticView_id, null,
						IWorkbenchPage.VIEW_VISIBLE);
			} catch (PartInitException e) {
				MessageDialog.openError(window.getShell(), "出错", "无法打开视图！");
			}
			break;
		case 6:
			try {
				window.getActivePage().showView(
						IAppConstants.contactManagerView_id, null,
						IWorkbenchPage.VIEW_VISIBLE);
			} catch (PartInitException e) {
				MessageDialog.openError(window.getShell(), "出错", "无法打开视图！");
			}
			break;
		case 7:
			try {
				window.getActivePage().showView(
						IAppConstants.goldCenterView_id, null,
						IWorkbenchPage.VIEW_VISIBLE);
			} catch (PartInitException e) {
				MessageDialog.openError(window.getShell(), "出错", "无法打开视图！");
			}
			break;
		case 8:
			try {
				window.getActivePage().showView(
						IAppConstants.systemPropertyView_id, null,
						IWorkbenchPage.VIEW_VISIBLE);
			} catch (PartInitException e) {
				MessageDialog.openError(window.getShell(), "出错", "无法打开视图！");
			}
			break;
		}

	}

}
